﻿// -----------------------------------------------------------------------
// <copyright file="DateTimePluralizerTest.cs" company="Moveax, LLC">
// Copyright (c) 2013 Andrey Veselov. All rights reserved.
// License:  Microsoft Public License (MS-PL)
// Contacts: http://andrey.moveax.com andrey@moveax.com
// </copyright>
// -----------------------------------------------------------------------

namespace Moveax.Pluralization.Tests
{
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Moveax.Pluralization.Common;

    [TestClass]
    public class DateTimePluralizerTest
    {
        [TestMethod]
        public void HoursUnitsToString()
        {
            // Arrange
            const string expectedForInt = "hour";
            const string expectedForFloat = "hours";
            var pluralizer = new DateTimePluralizer(new CultureInfo("en-US"));

            // Act
            // calls should return "en" values for unsupported culture
            var actualForInt = pluralizer.GetStringFor(1, DateTimeUnit.Hours);
            var actualForFloat = pluralizer.GetStringFor(1.3f, DateTimeUnit.Hours);

            // Assert
            Assert.AreEqual(expectedForInt, actualForInt);
            Assert.AreEqual(expectedForFloat, actualForFloat);
        }


        [TestMethod]
        public void ValidateDateTimePluralizer_Ru() // using ru-RU as the most complicated rules
        {
            // Arrange
            var daysCount = new int[] { 1, 3, 5 };
            var expectedRu = new string[] { "день", "дня", "дней" };

            this.TestDateTimePluralizer("ru-RU", daysCount, expectedRu);
        }

        private void TestDateTimePluralizer(
            string cultureName, IList<int> daysCount, IList<string> expectedValues)
        {
            // Arrange
            var pluralizer = new DateTimePluralizer(new CultureInfo(cultureName));
            var count = daysCount.Count();
            var actual = new string[count];
            var actualNegative = new string[count];

            // Act
            for (var i = 0; i < count; i++) {
                actual[i] = pluralizer.GetStringFor(daysCount[i], DateTimeUnit.Days);
                actualNegative[i] = pluralizer.GetStringFor(-daysCount[i], DateTimeUnit.Days);
            }

            // Assert
            for (var i = 0; i < count; i++) {
                Assert.AreEqual(expectedValues[i], actual[i]);
                Assert.AreEqual(expectedValues[i], actualNegative[i]);
            }
        }
    }
}
